﻿using System;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using PackTracker.Business;
using System.Collections.Generic;

/// <summary>
/// WebServices that persist vehicle information on database
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class WSMonitoramento : System.Web.Services.WebService
{
    public WSMonitoramento()
    {
    }

    [WebMethod]
    public int MonitoramentoGravar(string idvehicle, string location, string items)
    {
        int returnValue = 0;
        /*
        try
        {

            Veiculo veiculo = Veiculo.GetVeiculo(idvehicle);
            PackTracker.Business.Monitoramento monitoramento = PackTracker.Business.Monitoramento.NewMonitoramento();
            monitoramento.IdVeiculo = veiculo.Id;
            monitoramento.DataString = DateTime.Now.ToString();

            //Get all order items
            List<string> orderItems = new List<string>(items.Split('|'));
            foreach (string orderItem in orderItems)
            {
                //Add order item to monitoring item
                ItemPedido item = ItemPedido.GetItemPedido(1);
                ItemMonitoramento itemMonitoramento = ItemMonitoramento.NewItemMonitoramento();

                itemMonitoramento.IdItemPedido = item.Id;
                itemMonitoramento.IdMonitoramento = monitoramento.Id;
                itemMonitoramento.Save();

                monitoramento.ItensMonitoramento.Add(itemMonitoramento);
            }

            //Get location
            List<string> locationPositions = new List<string>(location.Split('|'));

            if (locationPositions.Count == 3)
            {
                monitoramento.Altitude  = int.Parse(locationPositions[0]);
                monitoramento.Latitude  = locationPositions[1];
                monitoramento.Longitude = locationPositions[2];
            }

            monitoramento.Save();

            returnValue = 1;
        }
        catch {}
        */
        return returnValue;
    }

}

